package org.excample.service.impl;

import com.github.pagehelper.Page;
import org.excample.entity.WorkShop;
import org.excample.mapper.WorkshopMapper;
import org.excample.service.WorkShopService;
import org.springframework.beans.factory.annotation.Autowired;

import java.awt.print.Pageable;
import java.util.List;
import java.util.Optional;

public class WorkShopServiceImpl implements WorkShopService {

    private final WorkShopService workShopService;
    public WorkShopServiceImpl(WorkShopService workShopService) {
        this.workShopService = workShopService;
    }
    // 保存车间信息到数据库中
    public void saveWorkShop(WorkShop workShop) {
        WorkShopService.saveWorkShop(workShop);
    }
    // 更新车间信息到数据库中
    public void updateWorkShop(WorkShop workShop) {
        Optional<WorkShop> existingWorkShop = workShopService.findById();
        if (existingWorkShop.isPresent()) {
            WorkShopService.saveWorkShop(workShop);
        } else {
            throw new RuntimeException("车间信息不存在");
        }
    }
    // 删除车间信息从数据库中
    public void deleteWorkShop(Long id) {
        workShopService.deleteWorkShop(id);
    }

    @Override
    public List<WorkShop> findWorkShopsWithPagination(int offset, int size) {
        return List.of();
    }

    @Override
    public Page<WorkShop> getWorkShopsByPage(Pageable pageable) {
        return null;
    }

    @Override
    public Optional<WorkShop> findById() {
        return Optional.empty();
    }

    // 可以根据需要添加其他方法，例如根据ID查询车间信息
    public WorkShop findWorkShopById(Long id) {
        return workShopService.findById().orElseThrow(() -> new RuntimeException("车间信息不存在"));
    }

    //分页展示：支持前端请求时指定的页码和每页显示的记录数，返回对应页码的车间记录列表。
    public List<WorkShop> getWorkShops(int page, int size) {
        int offset = (page - 1) * size;
        return workShopService.findWorkShopsWithPagination(offset, size);
    }
}
